#!/bin/bash
scriptPath=$(cd $(dirname $0) && pwd)
projectPath=$(cd $(dirname $0)/.. && pwd)
projectName="${projectPath##*/}"
templatePath=${scriptPath}/template

#初始化git信息
${scriptPath}/git.sh

# 项目文件
if test ! -d ${projectPath}/.vscode ; then
    cp -r ${templatePath}/.vscode ${projectPath}/.vscode
fi

# 忽略文件
if test ! -f ${projectPath}/.gitignore ; then
    cp ${templatePath}/.gitignore ${projectPath}/.gitignore
fi

# 说明文件
if test ! -f ${projectPath}/README.md ; then
    echo "# ${projectName}" > ${projectPath}/README.md
fi

# package.json
if test ! -f ${projectPath}/package.json ; then
    cp ${templatePath}/package.json ${projectPath}/package.json
fi

# tsconfig.json
if test ! -f ${projectPath}/tsconfig.json ; then
    cp ${templatePath}/tsconfig.json ${projectPath}/tsconfig.json
fi

# 配置目录
if test ! -d ${projectPath}/config ; then
    mkdir -p ${projectPath}/config
fi

# 日志目录
if test ! -d ${projectPath}/logs ; then
    mkdir -p ${projectPath}/logs
    echo "*" > ${projectPath}/logs/.gitignore
    echo "!.gitignore" >> ${projectPath}/logs/.gitignore
fi

# 测试目录
if test ! -d ${projectPath}/tests ; then
    mkdir -p ${projectPath}/tests
fi

# 资源目录
if test ! -d ${projectPath}/resources ; then
    mkdir -p ${projectPath}/resources
fi

# 源码目录
if test ! -d ${projectPath}/src ; then
    cp -r ${templatePath}/src ${projectPath}/src
fi

cd ${projectPath}
npm install
